package com.jsbb.controller.sys;

import com.jsbb.annotation.ApiLog;
import com.jsbb.common.Message;
import com.jsbb.dto.sys.SysRoleQueryDto;
import com.jsbb.dto.sys.SysRoleSaveDto;
import com.jsbb.dto.sys.SysRoleUpdateDto;
import com.jsbb.service.sys.SysRoleService;
import com.jsbb.vo.PageVo;
import com.jsbb.vo.sys.SysRoleDetailVo;
import com.jsbb.vo.sys.SysRoleListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色管理Controller
 *
 * @author w
 * @date 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/sys/role")
@ApiLog("角色管理")
@Api(tags = {"2.2 系统管理-角色管理"})
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @PostMapping("/all")
    @ApiOperation(value = "获取列表，不分页")
    public Message<List<SysRoleListVo>> all() {
        List<SysRoleListVo> list = sysRoleService.selectAll();
        return Message.success(list);
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取列表")
    public Message<PageVo<SysRoleListVo>> list(@Validated @RequestBody SysRoleQueryDto sysRoleQueryDto) {
        PageVo<SysRoleListVo> pageVo = sysRoleService.list(sysRoleQueryDto);
        return Message.success(pageVo);
    }

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取详情")
    public Message<SysRoleDetailVo> get(@PathVariable("id") Long id) {
        SysRoleDetailVo sysRoleDetailVo = sysRoleService.get(id);
        return Message.success(sysRoleDetailVo);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增")
    public Message save(@Validated @RequestBody SysRoleSaveDto saveDto) {
        sysRoleService.save(saveDto);
        return Message.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Message update(@Validated @RequestBody SysRoleUpdateDto updateDto) {
        sysRoleService.update(updateDto);
        return Message.success();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public Message delete(@PathVariable("id") Long id) {
        sysRoleService.delete(id);
        return Message.success();
    }
}
